/*
Source : https://leetcode.com/problems/binary-tree-inorder-traversal/
Author : nflush@outlook.com
Date   : 2016-07-05
*/

/*
94. Binary Tree Inorder Traversal

    Total Accepted: 132859
    Total Submissions: 327375
    Difficulty: Medium

Given a binary tree, return the inorder traversal of its nodes' values.

For example:
Given binary tree [1,null,2,3],

   1
    \
     2
    /
   3

return [1,3,2].

Note: Recursive solution is trivial, could you do it iteratively?

Subscribe to see which companies asked this question
*/

/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
 * };
 */
class Solution {
private:
    void insertNode(vector<int> &ret, TreeNode* tr){
        if (tr){
            insertNode(ret, tr->left);
            ret.push_back(tr->val);
            insertNode(ret, tr->right);
        }
    }
public:
    vector<int> inorderTraversal(TreeNode* root) {
        vector<int> ret;
        insertNode(ret, root);
        return ret;
    }
};

